package org.hishenframework.web.validate.jqvalidate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

public class SimpleJsr2JqValidatorCollection implements Jsr2JqValidatorCollection {
	
	private Map<Class<?>, Jsr2JqValidate> java2JqValidatorsMap = new HashMap<Class<?>, Jsr2JqValidate>();
	private List<Jsr2JqValidate> java2JqValidators;
	
	@PostConstruct
	private void init() {
		//从Java2JqValidator的getAnnotationType方法获取该验证类对应的jsr303类型
		//使用类型作为key放入map中进行匹配
		for (Jsr2JqValidate v : java2JqValidators) {
			java2JqValidatorsMap.put(v.getAnnotationType(), v);
		}
	}

	public void setJava2JqValidators(List<Jsr2JqValidate> java2JqValidators) {
		this.java2JqValidators = java2JqValidators;
	}

	@Override
	public Jsr2JqValidate get(Class<?> jsrAnnotation) {
		return java2JqValidatorsMap.get(jsrAnnotation);
	}
	
}
